import { Component, OnInit, Injector, ViewChild, EventEmitter, Output } from '@angular/core';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import {
    StockZT_MaintainBillItemServiceProxy
} from '@shared/service-proxies/stock-service-proxies';
import * as _ from 'lodash';

import { ModalDirective } from 'ngx-bootstrap';
import { finalize } from 'rxjs/operators';

@Component({
    templateUrl: './update-status-modal.component.html',
    animations: [appModuleAnimation()],
    selector: 'updateMaintainToolingStatus'
})
export class UpdateMaintainToolingStatusModalComponent extends AppComponentBase implements OnInit {
    @ViewChild('createOrEditModal') modal: ModalDirective;
    @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();
    constructor(injector: Injector, private _billService: StockZT_MaintainBillItemServiceProxy) {
        super(injector);
    }

    saving = false;
    closed = false;
    active = false;
    id;
    status = [{ label: '未维修', value: 0 }, { label: '已维修', value: 1 }, { label: '无法维修', value: 2 }];
    statu;
    show(event): void {
        this.closed = false;
        this.active = true;
        this.id=event;
        this.modal.show();
    }

    close(): void {
        this.active = false;
        this.modal.hide();
    }
    save(): void {
        this.saving = true;

        this._billService
            .updateMaintainStatus(this.id,this.statu)
            .pipe(
                finalize(() => {
                    this.saving = false;
                })
            )
            .subscribe(() => {
                this.notify.info(this.l('SavedSuccessfully'));
                this.close();
                this.modalSave.emit(null);
            });
    }
    ngOnInit() {}

    onHidden(event) {
        this.closed = true;
    }
}
